<template>
  <div>
    <el-form ref="form" :model="form" label-width="130px" disabled>
      <el-form-item label="发布模式：" prop="publishMode">
        <el-select v-model="form.publishMode" class="min-select" clearable>
          <el-option :value="0" label="快捷发布模式" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否单独销售：" required>
        <el-switch
          v-model="form.isSeparateSales"
          :active-value="1"
          :inactive-value="0"
          active-text="是"
          inactive-text="否"
        />
      </el-form-item>
      <el-form-item label="游玩日期分段：" required>
        <el-switch
          v-model="form.isTimePhased"
          :active-value="1"
          :inactive-value="0"
          active-text="是"
          inactive-text="否"
        />
      </el-form-item>
      <el-form-item label="预定时间段：" prop="reserveDate">
        <el-date-picker
          v-model="form.reserveDate"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item v-if="form.isTimePhased === 0" key="timeRules" prop="timePeriod">
        <el-table border :data="[form.timeRules[0]]">
          <el-table-column label="成本价（元）">
            <template slot-scope="scope">
              <el-input v-model="scope.row.costPrice" placeholder="请输入" clearable />
            </template>
          </el-table-column>
          <el-table-column label="零售价（元）">
            <template slot-scope="scope">
              <el-input v-model="scope.row.retailPrice" placeholder="请输入" clearable />
            </template>
          </el-table-column>
          <el-table-column label="门市价（元）">
            <template slot-scope="scope">
              <el-input v-model="scope.row.doorMarketPrice" placeholder="请输入" clearable />
            </template>
          </el-table-column>
          <el-table-column label="库存">
            <template slot-scope="scope">
              <el-input v-model="scope.row.dailyInventory" placeholder="请输入" clearable />
            </template>
          </el-table-column>
        </el-table>
      </el-form-item>
      <el-form-item v-if="form.isTimePhased === 1" key="timeListPeriod" prop="timeListPeriod">
        <div v-for="(item,index) in form.timeRules" :key="index">
          <el-radio-group v-model="item.radio" label="">
            <el-radio :label="8">全选</el-radio>
            <el-radio :label="9">工作日</el-radio>
            <el-radio :label="10">周末</el-radio>
          </el-radio-group>
          <el-form-item label="">
            <el-checkbox-group v-model="item.weekdaySet">
              <el-checkbox :label="1">周一</el-checkbox>
              <el-checkbox :label="2">周二</el-checkbox>
              <el-checkbox :label="3">周三</el-checkbox>
              <el-checkbox :label="4">周四</el-checkbox>
              <el-checkbox :label="5">周五</el-checkbox>
              <el-checkbox :label="6">周六</el-checkbox>
              <el-checkbox :label="7">周日</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-table border :data="[item]">
            <el-table-column label="成本价（元）">
              <template slot-scope="scope">
                <el-input v-model="scope.row.costPrice" placeholder="请输入" clearable />
              </template>
            </el-table-column>
            <el-table-column label="零售价（元）">
              <template slot-scope="scope">
                <el-input v-model="scope.row.retailPrice" placeholder="请输入" clearable />
              </template>
            </el-table-column>
            <el-table-column label="门市价（元）">
              <template slot-scope="scope">
                <el-input v-model="scope.row.doorMarketPrice" placeholder="请输入" clearable />
              </template>
            </el-table-column>
            <el-table-column label="库存">
              <template slot-scope="scope">
                <el-input v-model="scope.row.dailyInventory" placeholder="请输入" clearable />
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-form-item>
      <el-form-item label="门票有效期：" required>
        <el-radio-group v-model="form.ticketValidity">
          <el-radio :label="0">游玩日期当天有效</el-radio>
          <el-radio :label="1">游玩日期至指定日期</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="form.ticketValidity === 1" label="" prop="endValidityDate">
        游玩日期（含）至
        <el-date-picker
          v-model="form.endValidityDate"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择"
          type="datetime"
          default-time="23:59:59"
        />
        有效
      </el-form-item>
      <el-form-item label="需提前下单：" required>
        <el-radio-group v-model="form.isPlaceOrderInAdvance">
          <el-radio :label="0">否</el-radio>
          <el-radio :label="1">是</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="form.isPlaceOrderInAdvance === 1" label="" prop="placeOrderTime">
        至少需提前1天，并在
        <el-time-picker
          v-model="form.placeOrderTime"
          value-format="HH:mm:ss"
          placeholder="请选择"
        />
      </el-form-item>
      <el-form-item label="下单数量：" required>
        <el-radio-group v-model="form.orderQuantity">
          <el-radio :label="0">不限</el-radio>
          <el-radio :label="1">限制</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="form.orderQuantity === 1" label="" prop="quantity">
        <el-col :span="20">
          每次下单，最少
          <el-input v-model="form.leastQuantity" placeholder="请输入" class="min-input" />
          最多
          <el-input v-model="form.mostQuantity" placeholder="请输入" class="min-input" />
        </el-col>
      </el-form-item>
      <el-form-item label="取票入园：" required>
        <el-switch
          v-model="form.admissionRule"
          :active-value="1"
          :inactive-value="0"
          active-text="是"
          inactive-text="否"
        />
      </el-form-item>
      <el-form-item label="退票规则：" required>
        <el-radio-group v-model="form.returnTicketRule">
          <el-radio :label="0">随时退</el-radio>
          <el-radio :label="1">有条件退</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="短信通知：">
        <el-checkbox-group v-model="form.notice">
          <el-checkbox :label="1">订单出票，短信通知游客</el-checkbox>
          <el-checkbox :label="2">游客主动取消订单，短信通知游客</el-checkbox>
          <el-checkbox :label="3">取消订单，短信通知游客</el-checkbox>
        </el-checkbox-group>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

export default {
  name: 'Step2',
  components: {},
  props: {
    formDetail: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      form: {
        publishMode: '',
        isSeparateSales: 0,
        isTimePhased: 0,
        reserveDate: '',
        timeRules: [{
          costPrice: '',
          retailPrice: '',
          doorMarketPrice: '',
          dailyInventory: '',
          radio: 8,
          weekdaySet: [1, 2, 3, 4, 5, 6, 7]
        }],
        ticketValidity: 0,
        endValidityDate: '',
        isPlaceOrderInAdvance: 0,
        placeOrderTime: '',
        orderQuantity: 0,
        leastQuantity: '',
        mostQuantity: '',
        admissionRule: 0,
        returnTicketRule: 0,
        notice: []
      }
    }
  },

  created() {
    const {
      publishMode,
      isSeparateSales,
      isTimePhased,
      productDateRuleCreateVOS,
      ticketValidity,
      endValidityDate,
      isPlaceOrderInAdvance,
      placeOrderTime,
      orderQuantity,
      leastQuantity,
      mostQuantity,
      admissionRule,
      returnTicketRule,
      notice
    } = this.formDetail
    const { startDate, endDate } = productDateRuleCreateVOS[0] || []
    const reserveDate = startDate && endDate ? [startDate, endDate] : ''
    this.form = {
      publishMode,
      isSeparateSales,
      isTimePhased,
      reserveDate,
      timeRules: productDateRuleCreateVOS[0].shopProductTimeRuleBaseVOS,
      ticketValidity,
      endValidityDate,
      isPlaceOrderInAdvance,
      placeOrderTime,
      orderQuantity,
      leastQuantity,
      mostQuantity,
      admissionRule,
      returnTicketRule,
      notice
    }
  },

  methods: {}
}
</script>
<style lang="scss" scoped>
.min-input {
  width: 110px;
  padding: 0 10px;
}
</style>
